using System;
using System.Collections.Generic;
using System.Text;

namespace BussinessLogicTecnoPez
{
    public class DateTimeManger
    {
        public enum DateInterval
        {
            Second, Minute, Hour, Day, Week, Month, Quarter, Year
        }
        public DateTimeManger()
        { }//end of default constructor

        public static long DateDiff(DateInterval Interval, System.DateTime StartDate,
                                                                    System.DateTime EndDate)
        {
            long lngDateDiffValue = 0;
            System.TimeSpan TS = new System.TimeSpan(EndDate.Ticks - StartDate.Ticks);
            switch (Interval)
            {
                case DateInterval.Day:
                    lngDateDiffValue = (long)TS.Days;
                    break;
                case DateInterval.Hour:
                    lngDateDiffValue = (long)TS.TotalHours;
                    break;
                case DateInterval.Minute:
                    lngDateDiffValue = (long)TS.TotalMinutes;
                    break;
                case DateInterval.Month:
                    lngDateDiffValue = (long)(TS.Days / 30);
                    break;
                case DateInterval.Quarter:
                    lngDateDiffValue = (long)((TS.Days / 30) / 3);
                    break;
                case DateInterval.Second:
                    lngDateDiffValue = (long)TS.TotalSeconds;
                    break;
                case DateInterval.Week:
                    lngDateDiffValue = (long)(TS.Days / 7);
                    break;
                case DateInterval.Year:
                    lngDateDiffValue = (long)(TS.Days / 365);
                    break;
            }
            return (lngDateDiffValue);
        }//end of DateDiff


        public static string convertirDecimalAHoraHumana(decimal horaParametro)
        {
            decimal hora = decimal.Truncate(horaParametro);
            decimal minutos = (horaParametro - decimal.Truncate(horaParametro)) * 60;
            minutos = decimal.Truncate(minutos);
            return hora.ToString().PadLeft(2, '0').Substring(0, 2) + ":" + minutos.ToString().PadLeft(2, '0').Substring(0, 2); ;
        }

        public static decimal convertirHoraHumanaADecimal(string horaHumana)
        {
            string[] partes = horaHumana.Split(':');
            decimal result = decimal.Parse(partes[0]);
            result = result + (decimal.Parse(partes[1]) / 60);
            return result;
        }
    }//end of class
}

